all:
	rm -rf ./bin/*.bin
	nasm -f aout ./src/libasm.asm -o32 -o ./bin/libasm.o
	nasm -f aout ./src/loader.asm -o32 -o ./bin/kstart.o
	gcc -fno-stack-protector -Wall -g -c -m32 ./src/kernel.c -o ./bin/kernel.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/libc.c  -o ./bin/libc.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/shell.c  -o ./bin/shell.o -fno-builtin -fno-stack-protector
	gcc -Wall -g -c -m32 ./src/io.c -o ./bin/io.o -fno-builtin -fno-stack-protector
	gcc -Wall -g -c -m32 ./src/string.c -o ./bin/string.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/fd.c -o ./bin/fd.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/video.c -o ./bin/video.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/keyboard.c -o ./bin/keyboard.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/lsusb.c -o ./bin/lsusb.o -fno-builtin -fno-stack-protector
	gcc -Wall -g -c -m32 ./src/ctype.c -o ./bin/ctype.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/time.c -o ./bin/time.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/random.c -o ./bin/random.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/shutdown.c -o ./bin/shutdown.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/malloc.c -o ./bin/malloc.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/exception.c -o ./bin/exception.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/sched.c -o ./bin/sched.o -fno-builtin
	gcc -Wall -g -c -m32 ./src/proc.c -o ./bin/proc.o -fno-builtin -fno-stack-protector
	ld -T ./src/link.ld -melf_i386 -o ./bin/kernel.bin ./bin/kstart.o ./bin/kernel.o ./bin/shell.o ./bin/libc.o ./bin/libasm.o ./bin/io.o ./bin/string.o ./bin/fd.o ./bin/video.o ./bin/keyboard.o ./bin/ctype.o ./bin/lsusb.o ./bin/time.o ./bin/random.o ./bin/malloc.o ./bin/shutdown.o ./bin/exception.o ./bin/sched.o ./bin/proc.o
	mcopy ./bin/kernel.bin d:boot/ -o

bochs:
	$(MAKE) all
	mcopy ./bin/kernel.bin d:boot/ -o
	bochs -qf bochsrc.txt

cd:
	$(MAKE) clean
	$(MAKE) all
	mcopy ./bin/kernel.bin d:boot/ -o
	mkisofs -U -D -floppy-boot -b  tpe.img -c boot.catalog -hide tpe.img -hide boot.catalog -V "TPE" -iso-level 3 -L -o ./iso/tpe.iso ./img/

clean:
# 	$(MAKE) clean -C src
	rm -rf ./bin/*.bin *~ .doc/*

docu:
	$(MAKE) clean
	python ./scripts/doc.py > doc.tex
	pdflatex doc.tex
	pdflatex doc.tex
	mv doc.pdf ./doc/doc.pdf
	rm doc.*
	kpdf ./doc/doc.pdf

cexe:
	$(MAKE) clean
	$(MAKE) all
	mcopy ./bin/kernel.bin d:boot/ -o
	bochs -qf bochsrc.txt

qemu:
	$(MAKE) clean
	$(MAKE) all
	mcopy ./bin/kernel.bin d:boot/ -o
	cp bin/kernel.bin bin/kernel.s
	qemu -usb -m 32  -fda img/tpe.img

vmware:
	$(MAKE) clean
	$(MAKE) all
	mcopy ./bin/kernel.bin d:boot/ -o
	cp bin/kernel.bin bin/kernel.s
	vmplayer ./MS-DOS/MS-DOS.vmx&

cdebug:
	$(MAKE) clean
	$(MAKE) all
	mcopy ./bin/kernel.bin d:boot/ -o
	cp bin/kernel.bin bin/kernel.s
	qemu -usb -s -p 5000 -m 32 -fda img/tpe.img -no-kqemu &
	sleep 2
	gdb bin/kernel.s --eval-command="target remote localhost:5000" --eval-command="b kmain"  --eval-command="c"

debug:
	$(MAKE) all
	mcopy ./bin/kernel.bin d:boot/ -o
	cp bin/kernel.bin bin/kernel.s
	qemu -usb -s -p 5000 -m 32 -fda img/tpe.img -no-kqemu &
	sleep 2
	gdb bin/kernel.s --eval-command="target remote localhost:5000" --eval-command="b kmain"  --eval-command="c"

tdebug:	$(make) all
	mcopy ./bin/kernel.bin d:boot/ -o
	cp bin/kernel.bin bin/kernel.s
	qemu -usb -s -p 5000 -m 32 -fda img/tpe.img &
	sleep 2
	gdb bin/kernel.s --eval-command="target remote localhost:5000" --eval-command="b kmain"  --eval-command="c"

